Repository navigation
feat(route-proxy): complimentary-token metering wall for openai-payg-free (#13839) - #14025
Merged
Merged
Conversation
…free (#13839) The free alias draws on OpenAI's daily complimentary buckets (large group 1M tokens/day, reset 00:00 UTC) whose exhaustion is silent — traffic just starts billing — so no failure-driven wall could ever fire for it. Now the proxy counts the day's usage per group from the route_attempt ledger (tokens_input + tokens_output, the response's total; reasoning/cache tokens are subsets of those and count exactly once) and walls the alias's pairs at bucket minus margin until the 00:00 UTC reset, inside the existing seating gate. The counter is the ledger, so it survives restarts by construction. Unlike the failure-driven walls, the gate's walk-anyway bypass never resurrects a metered pair: fail closed, or the wall would bill the balance it exists to protect. Config: a tokenMetering declaration on the openai-payg-free block (large group, 1M/day, 20K margin, all three catalog models). Checker: fail-closed validation of the declaration — shape, margin < bucket, every catalog model mapped to exactly one group, no mapped model outside the catalog. Tests (each names its oracle): counting accuracy against the fixture leaf's constant usage payload, wall engagement exactly at bucket minus margin with reasoning counted once, group separation, reset at 00:00 UTC on a pinned clock, fail-closed with no fall-through leg, and counter persistence across a proxy restart. Proxy suite 85/85, route-rules suite 52/52, all opencode-config-guard checks pass on the real config. Closes #13839
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 48 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the metering wall from #13839 (the issue body carries the full problem statement; this is its smallest version, landed).
What was missing:
openai-payg-freedraws on OpenAI's daily complimentary buckets (large group 1M tokens/day, small 10M/day, reset 00:00 UTC). Exhaustion is silent — no error, traffic just bills — and every wall the estate had was failure-driven, so none could ever fire for this alias. Drew's scope clarification (2026-11-23): count from response usage in the route proxy, fail closed at the bucket, no balance-polling, paid tails untouched.What this does:
route_attemptledger:tokens_input + tokens_outputover the alias's attempts started that day. Those are the response's prompt/completion totals; reasoning tokens (a completion subset) and cached tokens (a prompt subset) are already inside and count exactly once. The counter is the ledger, so it survives proxy/server restarts by construction and also counts session traffic on the alias (same provider id, same org bucket).applyKnownExhaustedGate) until the next 00:00 UTC; routes fall through to theopenai-paygpaid tail. One deliberate difference from the failure-driven walls: the gate's walk-anyway bypass never resurrects a metered pair — if nothing else survives, the route answers no-available-members rather than billing the free alias (fail closed).tokenMeteringdeclaration on theopenai-payg-freeblock, next to the alias: large group, 1,000,000 dailyTokens, 20,000 marginTokens, all three catalog models mapped. The margin exists because a request crossing the bucket bills in full; the wall stops new requests at the cap and does not try to predict request sizes.inspectProviderMeteringRulesin the route-rules guard: declaration shape,marginTokens < dailyTokens, every catalog model mapped to exactly one group, no mapped model outside the catalog (fail closed, mirroring the proxy's warn-and-never-engage for malformed declarations).Tests (each names its oracle in its title/comment):
Local runs: proxy suite 85/85, route-rules suite 52/52, the remaining config-guard suites 91/91, and all three guards pass on the real
.opencode/opencode.jsonc. CI runs on main per repo policy; the nightlyopencode-config-guardcovers these fixtures.Closes #13839
{ "direct_parent": null, "links": [], "lineage": { "design": null, "roadmap_item": null, "priority": null }, "pm_meta": 1, "provenance": { "queue_id": null, "scheduled_start": null, "picked_up_at": null, "work_started_at": null, "created_at": "2026-11-24T02:37:52Z", "session_id": null, "lane": null, "host": "htch-runtime", "worktree": "/home/hatch/workspace/lanes/lane-a/code-wt-13839", "model": null, "lane_start_issues": [], "workspace_ref": { "kind": "worktree", "id": "/home/hatch/workspace/lanes/lane-a/code-wt-13839", "repo": "developing-today/code", "branch": "lane/metering-wall-13839", "sha": "aa147d6ac350ba104d9a7d9d012f555c3bea7ffe" }, "auth_subject": "archer", "stamped_by": "fleet 0.1.0 (native)" } }Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.